/**
 * @author zhangxiaofei [<1326336909@qq.com>]
 * @dateTime 2023-02-12
 *
 * 基础组合钩子
 */
import I18n from "@/lang/index"
import { useRouter } from "vue-router"
import { useStore } from "@/hooks/store/useStore"

export const useBase = () => {

  /**
   * 路由器对象
   */
  const router = useRouter();

  /**
   * 国际化对象
   */
  const i18n = I18n.global.t

  /**
   * @author zhangxiaofei [<1326336909@qq.com>]
   * @dateTime 2023-02-12
   *
   * 获取当前请求参数对象
   *
   * @return {[type]}
   */
  const query = router.currentRoute.value.query

  /**
   * @author zhangxiaofei [<1326336909@qq.com>]
   * @dateTime 2023-02-12
   *
   * 权限验证
   *
   * @param {[type]} permission 权限
   * @return {[type]}
   */
  const isAuth = (data) => {
    const { permission } = useStore()

    // 获取用户权限列表
    const permissions = permission.permissionlist || ref([]);

    // 返回当前用户是否有权限
    return (permissions.indexOf(data) !== -1 || false);
  }


  return {
    isAuth,
    router,
    query,
    i18n,
  }
}
